home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 18 / CU Amiga Magazine's Super CD-ROM 18 (1997)(EMAP Images)(GB)[!][issue 1998-01].iso / CUCD / Programming / AmigaE / Src / Afc / Worldbuilder_Example2.e < prev   
Encoding:
Text File  |  1997-08-02  |  5.1 KB  |  175 lines

  1.  
  2. MODULE 'AFC/worldbuilder',
  3.        'AFC/bitmapper',
  4.        'AFC/explain_exception',
  5.        'intuition/intuition',
  6.        'intuition/screens',
  7.        'graphics/view',
  8.        'exec/ports'
  9.  
  10.  
  11. PROC main() HANDLE
  12.   DEF scene:PTR TO worldbuilder, scr:PTR TO screen, win:PTR TO window
  13.   DEF vp:PTR TO viewport, ri:PTR TO rasinfo, scrbm, bm2:PTR TO bitmapper
  14.   DEF rp2, bitmap2, port:PTR TO mp, usebm=0, rp
  15.   DEF rrx, rry, rrz, oox, ooy, ooz
  16.  
  17.   NEW scene.worldbuilder()
  18.  
  19.   scene.addobj('A')
  20.   scene.addobj('N')
  21.   scene.addobj('D')
  22.   scene.addobj('R')
  23.   scene.addobj('E')
  24.   scene.addobj('A2')
  25.  
  26.  
  27.   scene.fastsetvert('A',[-10,0,0, -20,0,0, -20,60,0, 20,60,0, 20,0,0,
  28.                           10,0,0, 10,30,0, -10,30,0, -10,50,0, 10,50,0,
  29.                           10,40,0, -10,40,0]:vertex_obj)
  30.  
  31.   scene.setsurface('A',0,[0,1,2,3,4,5,6,7],3)
  32.   scene.setsurface('A',1,[8,9,10,11],0)
  33.   scene.setsurface('A',2,[7,6,5,4,3,2,1,0],3)
  34.   scene.setsurface('A',3,[11,10,9,8],0)
  35.  
  36.   scene.fastsetvert('N',[-20,0,0, -20,60,0, -10,60,0, 10,10,0, 10,60,0,
  37.                          20,60,0, 20,0,0, 10,0,0, -10,50,0, -10,0,0]:vertex_obj)
  38.  
  39.   scene.setsurface('N',0,[0,1,2,3,4,5,6,7,8,9],3)
  40.   scene.setsurface('N',1,[9,8,7,6,5,4,3,2,1,0],3)
  41.  
  42.  
  43.   scene.fastsetvert('D',[-20,0,0, -20,60,0, 10,60,0, 20,50,0, 20,10,0,
  44.                          10,0,0, -10,10,0, -10,50,0, 0,50,0, 10,40,0,
  45.                          10,20,0, 0,10,0]:vertex_obj)
  46.  
  47.   scene.setsurface('D',0,[0,1,2,3,4,5],3)
  48.   scene.setsurface('D',1,[6,7,8,9,10,11],0)
  49.   scene.setsurface('D',2,[5,4,3,2,1,0],3)
  50.   scene.setsurface('D',3,[11,10,9,8,7,6],0)
  51.  
  52.  
  53.   scene.fastsetvert('R',[-20,0,0, -20,60,0, 10,60,0, 20,50,0, 20,40,0,
  54.                          10,30,0, 20,0,0, 10,0,0, 0,30,0, -10,30,0,
  55.                          -10,0,0, -10,40,0, -10,50,0, 0,50,0, 0,40,0]:vertex_obj)
  56.  
  57.   scene.setsurface('R',0,[0,1,2,3,4,5,6,7,8,9,10],3)
  58.   scene.setsurface('R',1,[11,12,13,14],0)
  59.   scene.setsurface('R',2,[10,9,8,7,6,5,4,3,2,1,0],3)
  60.   scene.setsurface('R',3,[14,13,12,11],0)
  61.  
  62.  
  63.   scene.fastsetvert('E',[-20,0,0, -20,60,0, 20,60,0, 20,50,0, -10,50,0,
  64.                          -10,40,0, 0,40,0, 0,30,0, -10,30,0, -10,10,0,
  65.                          20,10,0, 20,0,0]:vertex_obj)
  66.  
  67.   scene.setsurface('E',0,[0,1,2,3,4,5,6,7,8,9,10,11],3)
  68.   scene.setsurface('E',1,[11,10,9,8,7,6,5,4,3,2,1,0],3)
  69.  
  70.   scene.copyobj('A','A2')
  71.  
  72.   scene.position('A',-140,-30,0)
  73.   scene.position('N',-90,-30,0)
  74.   scene.position('D',-40,-30,0)
  75.   scene.position('R',10,-30,0)
  76.   scene.position('E',60,-30,0)
  77.   scene.position('A2',110,-30,0)
  78.  
  79.   scene.applyobj('A')
  80.   scene.applyobj('N')
  81.   scene.applyobj('D')
  82.   scene.applyobj('R')
  83.   scene.applyobj('E')
  84.   scene.applyobj('A2')
  85.  
  86.   scene.setdisplay(320,256) -> display dimensions
  87.   scene.init3D() -> build system structures FOR filled vectors
  88.  
  89.   scene.setaftertrasl(160,128) -> origin OF the screen axes.
  90. ->  scene.setafterscale(200,200) -> scaling AFTER projection (TO fit in
  91.                                -> the screen): 200 = double.
  92.   scene.setobserver(0,0,-200)  -> position OF the observer
  93.  
  94.   -> we open a screen
  95.   scr:=OpenScreenTagList(NIL,[SA_TOP,0,
  96.                               SA_LEFT,0,
  97.                               SA_WIDTH,320,
  98.                               SA_HEIGHT,256,
  99.                               SA_DEPTH,3,
  100.                               SA_TITLE,'Routines3D',
  101.                               SA_SHOWTITLE,FALSE,
  102.                               0,0])
  103.   IF scr=NIL THEN Raise("SCR")
  104.   vp:=scr.viewport
  105.   ri:=vp.rasinfo    -> we get the rasinfo structure FOR double buffering
  106.   scrbm:=ri.bitmap
  107.  
  108.   -> a trivial palette
  109.   SetRGB4(vp,3,15,0,0)
  110.   SetRGB4(vp,4,0,15,0)
  111.   SetRGB4(vp,5,0,0,15)
  112.   SetRGB4(vp,7,12,12,0)
  113.  
  114.   -> we allocate a second bitmap FOR the double buffering
  115.   NEW bm2.bitmapper()
  116.   bm2.allocbitmap(320,256,3,TRUE)
  117.   rp2:=bm2.rastport()
  118.   bitmap2:=bm2.bitmap()
  119.  
  120.   -> the window IS needed TO get keypresses
  121.   win:=OpenWindowTagList(NIL,[WA_TOP,0,
  122.                               WA_LEFT,0,
  123.                               WA_WIDTH,320,
  124.                               WA_HEIGHT,256,
  125.                               WA_TITLE,'Routines3D',
  126.                               WA_FLAGS,WFLG_ACTIVATE OR WFLG_SMART_REFRESH OR WFLG_BACKDROP OR WFLG_BORDERLESS,
  127.                               WA_IDCMP,IDCMP_RAWKEY,
  128.                               WA_CUSTOMSCREEN,scr,
  129.                               0,0])
  130.   IF win=NIL THEN Raise("WIN")
  131.   rp:=win.rport
  132.   port:=win.userport
  133.  
  134.   oox:=0 ; ooy:=0 ; ooz:=-200  -> observer initial position
  135.   rrx:=0 ; rry:=0 ; rrz:=0  -> angles OF rotation
  136.  
  137.   ClearScreen(rp)
  138.   scene.projection()  -> project
  139.   scene.drawfill(rp)  -> AND draw the scene
  140.   usebm:=1-usebm
  141.  
  142.   FOR rry:=0 TO 359
  143.     scene.setrot(0,rry,0)
  144.     scene.projection()
  145.     SetAPen(IF usebm=0 THEN rp ELSE rp2, 0)
  146.     RectFill(IF usebm=0 THEN rp ELSE rp2, 0,30,320,200)
  147.     scene.drawfill(IF usebm=0 THEN rp ELSE rp2)
  148.  
  149.     IF usebm=0
  150.       ri.bitmap:=scrbm
  151.     ELSE
  152.       ri.bitmap:=bitmap2
  153.     ENDIF
  154.     WaitTOF()
  155.     ScrollVPort(vp)
  156.     usebm:=1-usebm
  157.   ENDFOR
  158.  
  159.   REPEAT
  160.     Delay(5)
  161.   UNTIL Mouse()
  162.  
  163. EXCEPT DO
  164.   IF win THEN CloseWindow(win)
  165.   IF scr
  166.     ri.bitmap:=scrbm
  167.     CloseScreen(scr)
  168.   ENDIF
  169.   IF scene THEN END scene  -> remember TO free ALL memory
  170.   IF bm2 THEN END bm2
  171.   explain_exception()
  172.   CleanUp(0)
  173. ENDPROC
  174.  
  175.